import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QToolBar, QAction, QFileDialog
from PyQt5.QtGui import QIcon



class MyWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        # 创建工具栏
        toolbar = self.addToolBar('My Toolbar')

        # 添加带有图标的按钮到工具栏
        action_open_file = QAction(QIcon('logo.png'), 'Open File', self)
        action_open_file.triggered.connect(self.openFile)
        toolbar.addAction(action_open_file)

        action_send_file = QAction(QIcon.fromTheme('document-save'), 'Send File', self)
        action_send_file.triggered.connect(self.sendFile)
        toolbar.addAction(action_send_file)

        self.setWindowTitle('QToolBar Example')
        self.setGeometry(200, 200, 400, 300)

    def openFile(self):
        # 打开文件选择对话框
        file_dialog = QFileDialog(self)
        file_path, _ = file_dialog.getOpenFileName(self, 'Open File')
        if file_path:
            print(f'Selected file: {file_path}')

    def sendFile(self):
        print('Send File button clicked')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MyWindow()
    window.show()
    sys.exit(app.exec_())
